<?php

namespace App\Http\Controllers;

use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Routing\Controller as BaseController;

class Controller extends BaseController
{
    use AuthorizesRequests, DispatchesJobs, ValidatesRequests;


    /**
     * @param int $code
     * @param string $msg
     * @param null $data
     * @return \Illuminate\Http\JsonResponse
     */
    final protected function success($code = 200, $msg = "", $data = null)
    {
        return response()->json([
            'code' => $code,
            'msg'  => $msg ? $msg : 'success',
            'data' => $data,
        ]);
    }

    /**
     * @param int $code
     * @param string $msg
     * @return \Illuminate\Http\JsonResponse
     */
    public function error($code = 300, $msg = "Service exception, please try again later")
    {
        return response()->json([
            'code' => $code,
            'msg'  => $msg
        ]);
    }

}
